# nap goi thu vien class
library(class)

# doc du lieu wpbc
iris <- read.table("iris.data",header=FALSE,sep=",")

nrow <- length(iris[,1])
ncol <- length(iris[1,])
tong<-0.0
for(i in 1:nrow)
{
	# lay ngau nhien
	idx <- sample(nrow, replace = FALSE)
	trainrow <- round(nrow-1)
	trainset <- iris[idx[1:trainrow],]
	testset <- iris[idx[nrow],]

	# goi knn voi k = 3
	pred <- knn(trainset[,-ncol], testset[,-ncol], trainset[,ncol], k=3)

	# tinh do chinh xac
	acc <- sum(pred == testset[,ncol])/(nrow - trainrow)
	tong<-tong+acc
}
print(tong/nrow)



